<template>
  <div class="visitor-notVisited">
    <div class="search-group">
      <div class="input-wrap">
        <div class="label">所属行业:</div>
        <div class="input-item">
          <el-cascader
            clearable
            placeholder="请选择所属行业"
            class="cascader tradeCascader"
            v-model="industryCas"
            :show-all-levels="false"
            :options="industryListTree"
            :props="{ label: 'informationName', value: 'id' }"
            @change="handleCasChange"
          ></el-cascader>
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">单位名称:</div>
        <div class="input-item">
          <a-input :maxLength="30" clearable v-model="queryParam.companyName" placeholder="请输入单位名称" />
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">退出时间:</div>
        <div class="time-item">
          <start-end-time
            :times="times"
            :showTime="{ format: 'HH:mm:ss' }"
            format="YYYY-MM-DD HH:mm:ss"
            @timeChange="timeChange"
            :resetTime="resetTime"
          ></start-end-time>
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">负责人:</div>
        <div class="input-item">
          <a-input :maxLength="30" clearable v-model="queryParam.legalPersonName" placeholder="请输入负责人" />
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">手机号码:</div>
        <div class="input-item">
          <a-input :maxLength="30" clearable v-model="queryParam.legalMobile" placeholder="请输入手机号码" />
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">身份证号:</div>
        <div class="input-item">
          <a-input :maxLength="18" v-model="queryParam.legalIdCard" placeholder="请输入身份证号" />
        </div>
      </div>

      <div class="btn-wrap">
        <a-button class="searchBtn" @click="searchQuery(queryParam.startTime, queryParam.endTime)" type="primary">
          搜索
        </a-button>
        <a-button class="resetBtn" @click="resetHandle()" type="primary"> 重置 </a-button>
      </div>
    </div>

    <div>
      <a-table
        rowKey="companyChangeRecordId"
        class="tableList"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        @change="handleTableChange"
      >
        <template #action="records">
          <!-- v-slot:action="records" -->
          <span class="operation deatil-color" v-has="'bank:detail'" @click="detailHandle(records)">详情 </span>
        </template>
      </a-table>
    </div>
  </div>
</template>
<script>
import moment from 'moment'
import { Cascader } from 'element-ui'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { comMethods } from '@/mixins/comMethods'
import startEndTime from '@/components/startEndTime'
import { informationPage } from '@/api/industry'
import { mapState } from 'vuex'
export default {
  name: 'visitor-notVisited',
  components: { startEndTime, 'el-cascader': Cascader },
  mixins: [JeecgListMixin, comMethods],
  computed: {
    ...mapState({
      isPoliceAgencyId: (state) => state.user.isPoliceAgencyId,
    }),
  },
  watch: {
    isPoliceAgencyId: {
      handler(v) {
        this.queryParam.policeAgencyId = v.id ? v.id : ''
        this.searchQuery()
      },
      immediate: true,
      deep: true,
    },
  },
  data() {
    return {
      url: {
        list: '/company/message/audit_page?companyStatus=4',
        tree: true,
      },
      industryCas: [],
      industryListTree: [],
      columns: [
        {
          title: '序号',
          align: 'center',
          width: 100,
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '所属派出所',
          dataIndex: 'policeAgencyId_dictText',
          ellipsis: true,
          align: 'center',
          customRender: (t) => {
            return (
              <a-tooltip placement="top">
                <template slot="title">
                  <span>{t}</span>
                </template>
                <div class="ant-table-row-cell-ellipsis">{t}</div>
              </a-tooltip>
            )
          },
        },
        {
          title: '单位名称',
          dataIndex: 'companyName',
          ellipsis: true,
          align: 'center',
          customRender: (t) => {
            return (
              <a-tooltip placement="top">
                <template slot="title">
                  <span>{t}</span>
                </template>
                <div class="ant-table-row-cell-ellipsis">{t}</div>
              </a-tooltip>
            )
          },
        },
        {
          title: '所属行业',
          dataIndex: 'industryInformationId_dictText',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '安全负责人',
          dataIndex: 'legalPersonName',
          ellipsis: true,
          align: 'center',
          customRender: (t) => {
            return (
              <a-tooltip placement="top">
                <template slot="title">
                  <span>{t}</span>
                </template>
                <div class="ant-table-row-cell-ellipsis">{t}</div>
              </a-tooltip>
            )
          },
        },
        {
          title: '联系电话',
          dataIndex: 'legalMobile',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '身份证号',
          dataIndex: 'legalIdCard',
          ellipsis: true,
          align: 'center',
          customRender: (t) => {
            return (
              <a-tooltip placement="top">
                <template slot="title">
                  <span>{t}</span>
                </template>
                <div class="ant-table-row-cell-ellipsis">{t}</div>
              </a-tooltip>
            )
          },
        },
        {
          title: '操作人员',
          dataIndex: 'outUserName',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '退出时间',
          dataIndex: 'outTime',
          ellipsis: true,
          width: 200,
          align: 'center',
        },
        {
          title: '操作',
          scopedSlots: { customRender: 'action' },
          align: 'center',
        },
      ],
    }
  },
  mounted() {
    this.industryCas = []
    this.getDictCas()
  },
  methods: {
    async getDictCas() {
      let { result } = await informationPage()
      this.industryListTree = this.deleteChildren(result)
    },
    deleteChildren(arr) {
      let childs = arr
      for (let i = childs.length; i--; i > 0) {
        if (childs[i].children) {
          if (childs[i].children.length) {
            this.deleteChildren(childs[i].children)
          } else {
            delete childs[i].children
          }
        }
      }
      return arr
    },
    handleCasChange(e) {
      this.queryParam.industryInformationId = e.slice(-1).toString()
    },
    resetHandle() {
      this.resetTime = true
      this.industryCas = []
      this.queryParam.industryInformationId = ''
      this.searchReset()
    },
    timeChange(v, index) {
      if (index == 1) {
        this.queryParam.startTime = this.$moment(v).valueOf()
      } else {
        this.queryParam.endTime = this.$moment(v).valueOf()
      }
      if (v == null) {
        this.queryParam.startTime = null
        this.queryParam.endTime = null
      }
    },
    // searchReset() {
    //   this.queryParam = {}
    //   this.resetTime = true
    //   this.loadData(1)
    // },
    // detailHandle(records) {
    //   records.isSuccess = false
    //   this.$refs.detailModal.show(records, 'refuseAudit')
    // },

    detailHandle(records) {
      // this.$refs.detailModal.show(records, 'alreadyAudit')
      this.$router.push({
        path: '/company/auditRecord/modules/exitManagement/detailModal',
        query: {
          companyMessageId: records.companyMessageId,
          companyChangeRecordId: records.companyChangeRecordId,
        },
      })
    },
  },
}
</script>
